package com.compmov.socialnetwork;


import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.compmov.datamodel.Persona;
import com.compmov.datamodel.TipoLugar;
import com.compmov.webservice.PersonaWSClient;
import com.compmov.webservice.TipoLugarWSClient;
import com.compmov.webservice.WSClientException;

public class Buscar extends Activity {
	double [] points=new double[]{19.5102,-99.1291, 19.5078,-99.1321,19.5112,-99.1253};

	private EditText nombre;
	private Spinner spinner;
	private CheckBox sugeridos;
	private CheckBox posicion;
	private Spinner ranking;

	private String val_nombre="";
	private String val_tipo="0";
	private String val_sugerido;
	private String val_posicion;
	private String val_ranking="0";

	public static final String TAG ="WEBSERVICE";	

	TipoLugarWSClient tipoLugarWS = new TipoLugarWSClient("tipolugar"); 


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		final String[] tiposLugares;
		final Integer[] idTiposLugares;

		super.onCreate(savedInstanceState);
		setContentView(R.layout.buscar);
		Bundle extras = getIntent().getExtras();
		String [] tipo = extras.getStringArray("tipo");
	

		spinner = (Spinner) findViewById(R.id.spinner);
		nombre = (EditText) findViewById(R.id.nombre_lugar);
		sugeridos=(CheckBox)findViewById(R.id.sugeridos);
		posicion=(CheckBox)findViewById(R.id.posicion);
		ranking=(Spinner)findViewById(R.id.ranking);

		
		if(tipo!=null){	
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
					this,android.R.layout.simple_spinner_item,tipo);
			adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			spinner.setAdapter(adapter);
		}
		
		
		ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
				this, R.array.numero_ranking, android.R.layout.simple_spinner_item);
		adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		ranking.setAdapter(adapter2);


	}

	public void BuscarLugar(View v){
		getValues();
		Intent intent = new Intent();
		intent.putExtra("nombre", val_nombre);
		intent.putExtra("tipo", val_tipo);
		intent.putExtra("sugeridos", val_sugerido);
		intent.putExtra("posicion", val_posicion);
		intent.putExtra("ranking", val_ranking);
		setResult(RESULT_OK, intent);
		finish();        
	}
	
	public void getValues(){
		val_nombre=nombre.getText().toString();	
		if(spinner.getSelectedItemPosition()!=-1)
			val_tipo=String.valueOf(spinner.getSelectedItemPosition());
		val_sugerido=String.valueOf(sugeridos.isChecked());
		val_posicion=String.valueOf(posicion.isChecked());
		if(ranking.getSelectedItemPosition()!=-1)
			val_ranking=String.valueOf(ranking.getSelectedItemPosition());		
	}



}